package com.u21.a0903_onlinemusic;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;

import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.u21.a0903_onlinemusic.adapter.CapAdapter;
import com.u21.a0903_onlinemusic.entity.Capital;
import com.u21.a0903_onlinemusic.words.Allwords;


public class WordLearningActivity extends Activity implements OnClickListener,
        OnItemClickListener {

    private final String[] caps = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
    private final int[] capsImg = {
            R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d,
            R.drawable.e, R.drawable.f, R.drawable.g, R.drawable.h,
            R.drawable.i, R.drawable.j, R.drawable.k, R.drawable.l,
            R.drawable.m, R.drawable.n, R.drawable.o, R.drawable.p,
            R.drawable.q, R.drawable.r, R.drawable.s, R.drawable.t,
            R.drawable.u, R.drawable.v, R.drawable.w, R.drawable.x,
            R.drawable.y, R.drawable.z,

    };
    private boolean isShowView = true;
    private GridView mGridView;
    private ListView mListView;
    private ArrayList<Capital> mArrayList;
    private ImageView mBtnSelectShow;
    private CapAdapter adapter;

    private ArrayList<ImageView> picViews = new ArrayList<ImageView>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wordmenu);
        mListView = findViewById(R.id.listview1);
        mGridView = findViewById(R.id.gridview1);
        mBtnSelectShow = findViewById(R.id.btn_select_show);


        initdata();
        mBtnSelectShow.setOnClickListener(this);
        adapter = new CapAdapter(this, mArrayList);
        setLayout();


    }


    //计时更换广告


    private void initdata() {
        mArrayList = new ArrayList<Capital>();
        for (int i = 0; i < 26; i++) {
            mArrayList.add(new Capital(caps[i], capsImg[i]));
        }
    }

    private void setLayout() {
        if (isShowView) {
            if (mGridView == null) {
                mGridView = (GridView) findViewById(R.id.gridview1);
            }
            mGridView.setVisibility(View.VISIBLE);
            mGridView.setAdapter(adapter);
            mGridView.setOnItemClickListener(this);
            mListView.setVisibility(View.GONE);
            mGridView.setSelection(0);
            isShowView = !isShowView;
        } else {
            if (mListView == null) {
                mListView = (ListView) findViewById(R.id.listview1);
            }
            mListView.setVisibility(View.VISIBLE);
            mListView.setAdapter(adapter);
            mListView.setOnItemClickListener(this);
            mGridView.setVisibility(View.GONE);
            mListView.setSelection(0);
            isShowView = !isShowView;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_select_show:
                setLayout();
                break;
            default:
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
                            long id) {
        switch (parent.getId()) {
            case R.id.gridview1:
            case R.id.listview1:
                Intent intent = new Intent(this, Allwords.class);
                intent.putExtra("Cap", mArrayList.get(position).getCapName());
                startActivity(intent);
                break;
            default:
                break;
        }

    }
}



//capAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arry);